package com.runda.partypolicy.app.page.fragment.task;

import android.annotation.SuppressLint;
import android.os.Bundle;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.runda.partypolicy.R;
import com.runda.partypolicy.app.base.BaseFragment;
import com.runda.partypolicy.app.page.adapter.Adapter_ListItem;
import com.runda.partypolicy.app.page.adapter.Adapter_OfficeList;
import com.runda.partypolicy.app.page.viewmodel.ViewModel_Task;
import com.runda.partypolicy.app.repository.bean.ItemListData;
import com.runda.partypolicy.app.repository.bean.OfficeData;


import java.util.ArrayList;
import java.util.List;

import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

;

/**
 * author:  RD_YH
 * date:    2019/3/15
 * version: v1.0
 */
public class Fragment_Task extends BaseFragment<ViewModel_Task> {

    List<ItemListData> dataList = new ArrayList<>();
    List<OfficeData> dataList2 = new ArrayList<>();
    @BindView(R.id.rv_content)
    RecyclerView rvContent;
//    private String[] texts = new String[]{"生育收养", "公共事业", "土地住房", "社会保障",

    //            "户籍办理", "教育科研", "入伍服役", "就业创业", "设立变更", "准营准办"};
//    private int[] iamges = new int[]{R.mipmap.icon_fertility_adoption, R.mipmap.icon_public_utilities, R.mipmap.icon_land_housing, R.mipmap.icon_social_security,
    private int[] iamges = new int[]{R.drawable.icon_qzf, R.drawable.icon_qw, R.drawable.icon_htjd, R.drawable.icon_gdjd, R.drawable.icon_kyjd,
    };
    private int[] urls = new int[]{R.drawable.icon_qzf};
    private Adapter_ListItem adapter;
    private Adapter_OfficeList adapter2;

    public static Fragment_Task newInstance(String type) {

        Bundle args = new Bundle();
        args.putString("type", type);
        Fragment_Task fragment = new Fragment_Task();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayout() {
        return  R.layout.fragment_task;
    }

    @Override
    public ViewModel_Task initViewModel() {
        return ViewModelProviders.of(this,getViewModelFactory()).get(ViewModel_Task.class);
    }

    @Override
    public void initEvents() {

    }

    @Override
    public void start() {
        initData();

    }

    @Override
    public void initNotSignEvent() {

    }

    @Override
    public void initNoNetworkEvent() {

    }

    @Override
    public void initShowMessageEvent() {

    }

    @Override
    public void initTokenOverTimeEvent() {

    }

    @Override
    public void initShowOrDismissWaitingEvent() {

    }

    @Override
    public void initStateLayoutEvent() {

    }

    @SuppressLint("WrongConstant")
    private void initData() {
        dataList.clear();
        String type = getArguments().getString("type");

        if ("待办".equals(type)) {
            ItemListData itemListData1 = new ItemListData(iamges[0], urls[0], "区政府主要领导交办的任务", "张西西", "2019年2月29日", "2020年3月", "2020年6月", "2019年2月29日", "区政府部门", "",
                    "", "", "", "", "", "0", "0");
            ItemListData itemListData2 = new ItemListData(iamges[1], urls[0], "区委主要领导交办的任务", "张西西", "2019年2月29日", "2020年3月", "2020年6月", "2019年2月29日", "区委部门", "",
                    "", "", "", "", "", "0", "0");
            dataList.add(itemListData2);
            dataList.add(itemListData1);

        } else if ("交办".equals(type)) {
            ItemListData itemListData3 = new ItemListData(iamges[0], urls[0], "区政府领导交办给区政府部门的任务", "朱贝贝", "2020年5月", "2020年5月", "2020年8月", "2019年2月29日", "区政府部门", "",
                    "2019.3.14 17 30", "朱贝贝", "", "", "", "2", "2");
            ItemListData itemListData4 = new ItemListData(iamges[1], urls[0], "区委领导交办给区委部门的任务", "朱贝贝", "2020年5月", "2020年5月", "2020年8月", "2019年2月29日", "区委部门", "",
                    "2019.3.14 17 30", "朱贝贝", "", "", "", "3", "2");

            dataList.add(itemListData4);
            dataList.add(itemListData3);
        } else if ("便捷".equals(type)) {
            ItemListData itemListData1 = new ItemListData(iamges[0], urls[0], "区政府部门请示区政府领导的事项", "张西西", "2019.03.22", "2019年3月29日", "2019年2月23日", "2019.03.29", "杨家埠旅游开发区", "",
                    "", "", "", "", "", "2", "3");

            ItemListData itemListData2 = new ItemListData(iamges[1], urls[0], "区委部门请示区委领导的事项", "张西西", "2019.03.22", "2019年3月22日", "2019年2月23日", "2019.03.22", "杨家埠旅游开发区", "",
                    "", "", "", "", "", "2", "3");


            dataList.add(itemListData2);
            dataList.add(itemListData1);
        }


        adapter = new Adapter_ListItem(R.layout.item_task, dataList);
        rvContent.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        rvContent.setAdapter(adapter);

            adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

//                    IntentUtil.startActivityWithOperation(getActivity(), ShowDetails.class, new IntentUtil.IntentOperation() {
//                        @Override
//                        public void operate(Intent intent) {
//
//                            if ("便捷".equals(type)) {
//
//                                intent.putExtra("title", "便捷请示");
//                            } else {
//
//                                intent.putExtra("title", "任务详情");
//                            }
//                            intent.putExtra("type", dataList.get(position).getUrl() + "");
//                            intent.putExtra("image", dataList.get(position).getUrl());
//
//                        }
//                    });


                }
            });



        if (adapter2 != null) {
            adapter2.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                    switch (position) {
                        case 0:
                        case 2:
                        case 1:

//                            IntentUtil.startActivityWithOperation(getActivity(), ShowDetails2.class, new IntentUtil.IntentOperation() {
//                                @Override
//                                public void operate(Intent intent) {
//                                    intent.putExtra("title", "公文批阅");
//                                    intent.putExtra("type", "公文批阅");
//                                }
//                            });
                            break;
                        default:
//                        IntentUtil.startActivityWithOperation(Activity_RequestReport.this, ShowDetails.class, new IntentUtil.IntentOperation() {
//                            @Override
//                            public void operate(Intent intent) {
//                                intent.putExtra("title", title);
//                                intent.putExtra("type", title);
//                            }
//                        });
                            break;
                    }
                }
            });

        }
    }



}
